package cn.regexp.demo.ui;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.BalloonBuilder;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.ui.awt.RelativePoint;
import lombok.Getter;

import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.List;

/**
 * @author Regexpei
 * @date 2024/6/10 18:38
 * @description
 */
public class ContentPanel {
    @Getter
    private JPanel container;
    private JTextField textField1;
    private JTextField textField2;
    private JCheckBox checkBox1;
    private JCheckBox checkBox2;
    private JComboBox<String> comboBox1;
    private JTextField textField3;
    private JPasswordField passwordField1;
    private JTextArea textArea1;
    private JTextArea textArea2;
    private JTable table1;
    private JLabel tip;

    private static final List<String> TOOLS = Arrays.asList("Java", "MySQL", "Redis");

    public ContentPanel() {
        textField1.setText("Regexpei");
        textField2.setText("Regexpei");
        checkBox1.setText("男");
        checkBox2.setText("女");

        comboBox1.addItem("请选择");
        for (String tool : TOOLS) {
            comboBox1.addItem(tool);
        }

        textField3.setText("这是一个文本输入框");
        passwordField1.setText("这是一个密码输入框");
        textArea1.setText("这是一个文本输入区");
        textArea2.setText("这是一个文本输入区");
        table1.addColumn(new TableColumn());


        tip.setIcon(AllIcons.General.Tip);
        tip.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // 点击事件
                Component component = e.getComponent();
                String content = "<p>这是一个提示。</p>  \n" +
                        "<p>This is a tip.</p>";
                JBColor color = new JBColor(Gray._240, Gray._240);
                BalloonBuilder builder = JBPopupFactory.getInstance()
                        /*
                            第一个参数：HTML 内容
                            第二个参数：图标
                            第三个参数：背景颜色
                            第四个参数：监听器
                         */
                        .createHtmlTextBalloonBuilder(content, null, color, null);

                // 设置 5 秒后隐藏
                builder.setFadeoutTime(5000)
                        // 设置边框颜色
                        .setBorderColor(color)
                        // 创建气泡
                        .createBalloon()
                        // 展示位置，相对与当前位置的下方
                        .show(new RelativePoint(component, new Point(8, component.getHeight())), Balloon.Position.below);
            }
        });
    }

}
